// import { reactive, ref } from "vue";
// import auth from "@/utils/auth";
// import { ElUpload, UploadFile } from "element-plus";

// export const useUpload = (data?: any, action?: string) => {
//   const uploadRef = ref<InstanceType<typeof ElUpload>>();
//   const uplodaData = reactive({
//     loading: false,
//     action: action || "/partner/upload/upload",
//     data: { type: 1, ...data },
//     fileList: [] as Base.File[],
//     headers: { auth: auth.get() },
//   });
//   const uploadBeforeUpload = (file: UploadFile) => {
//     console.log(file);
//     uplodaData.loading = true;
//   };
//   const uploadOnSuccess = (
//     response: UploadResponse,
//     file: UploadFile,
//     fileList: UploadFile[]
//   ) => {
//     console.log(response, file, fileList);
//     uplodaData.loading = false;
//   };
//   const uploadOnError = (
//     error: Error,
//     file: UploadFile,
//     fileList: UploadFile[]
//   ) => {
//     console.log(error, file, fileList);
//     uplodaData.loading = false;
//   };
//   const uploadOnPreview = (file: UploadFile) => {
//     console.log(1);
//     window.open(
//       file.response
//         ? (file.response as UploadResponse).result[0].url
//         : (file.url as string),
//       "_blank"
//     );
//   };
//   const uploadGetFileList = () => {
//     return (
//       (uplodaData.fileList as UploadFile[])
//         // .filter(i => !i.response || (i.response as UploadResponse).code === 1)
//         .map((i) => {
//           return {
//             name: i.name,
//             url: i.response
//               ? (i.response as UploadResponse).result[0].url
//               : (i.url as string),
//           };
//         }) || []
//     );
//   };
//   return {
//     uploadRef,
//     uplodaData,
//     uploadBeforeUpload,
//     uploadOnSuccess,
//     uploadOnError,
//     uploadOnPreview,
//     uploadGetFileList,
//   };
// };

// export const uploadGetFileList = (fileList: any[]) => {
//   return (
//     fileList.map((i) => {
//       return {
//         name: i.name,
//         url: i.response
//           ? (i.response as UploadResponse).result[0].url
//           : (i.url as string),
//       };
//     }) || []
//   );
// };

// interface UploadResponse {
//   errorCode: number | 1;
//   result: Base.File[];
// }
